<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/include/common_tag.jsp" %>
<div class="panel panel-default">
	<div class="panel-heading">
		<h3 class="panel-title">公司简介</h3>
	</div>
	<div class="panel-body">
		<form:form cssClass="form-horizontal" role="form" id="form">
			<div class="form-group">
				<input type="hidden" id="id" name="id" value="${companyProfileV.id}" />
				<label for="companyName" class="col-xs-12 col-sm-3 control-label no-padding-right">公司名称:</label>
				<div class="col-xs-12 col-sm-6">
					<input type="text" id="companyName" name="companyName"  class="width-100" value="${companyProfileV.companyName}" required=true  maxLength="50" />
					<span class="required">*</span>
				</div>
				
			</div>
			<div class="space-4"></div>
			<div class="form-group">
				<label for="username" class="col-xs-12 col-sm-3 control-label no-padding-right">公司图片:</label>
				<div class="col-xs-12 col-sm-6">
					<input type="hidden" id="imageUrl" name="imageUrl" class="width-100" value="${companyProfileV.imageUrl}"/>
					<div id="swfUploadContainer" style="width: 95%;">
					
					</div>
					<div>
						<img id="imagePreview" src="${companyProfileV.imageUrl}" alt="公司图片" style="display:none;width: 95%;"/>
					</div>
				</div>
				
			</div>
			<div class="space-4"></div>
			<div class="form-group">
				<label for="mobilePhone" class="col-xs-12 col-sm-3 control-label no-padding-right">公司信息:</label>
				<div class="col-xs-12 col-sm-6">
					<textarea class="form-control width-100" id="content" name="content" rows="10" style="width: 95%!important;">${companyProfileV.content}</textarea>
				</div>
				
			</div>
			<div class="space-12"></div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-11">
					<button id="returnBtn" type="button" class="btn btn-default btn-sm no-border">
						<i class="fa fa-undo"></i>重置
					</button>
					<button id="saveBtn" type="button" class="btn btn-success btn-sm no-border">
						<i class="fa fa-check"></i>提交
					</button>
				</div>
			</div>
		</form:form>
	</div>
	<script>
		$(function() {
			pageContents.find('#returnBtn').on('click', function() {
				$('#form').find('input').val('');
			});
			pageContents.find('#swfUploadContainer').tinyUploader({
				url : contextPath + '/file/upload',
				button_image_url: contextPath + '/images/uploadButton.jpg',
				dataType : 'text',
				onUploadSuccess : function(id, data) {
					imagePreview.attr('src', contextPath + '/' + data).show();
					pageContents.find('#imageUrl').val(data);
				}
			});
			var imagePreview = pageContents.find('#imagePreview');
			var id = pageContents.find('#id').val();
			if (id) {
				imagePreview.attr('src', contextPath + '/' + imagePreview.attr('src')).show();
			}
			pageContents.find('#saveBtn').on('click', function() {
				var $btn = $(this);
				if ($btn.hasClass('disabled')) {
					pageContents.find('#form').message({
						type : 'warning',
						content : '请不要重复提交!'
					});
					return;
				}
				$btn.addClass('disabled').attr('disabled', true);
				var companyName = pageContents.find('#companyName');
				var imageUrl = pageContents.find('#imageUrl');
				var content = pageContents.find('#content');
				var data = {
					companyName : companyName.val(),
					imageUrl : imageUrl.val(),
					content : content.val()
				}
				if (id) {
					data.id = id;
				}
				$.post(contextPath + '/companyProfile/save', data).done(function(data) {
					$btn.removeAttr('disabled').removeClass('disabled');
					if (data.statusCode == 20011011) {
						$('body').message({
							type : 'success',
							content : '保存成功'
						});
						$('[data-title="公司简介"]').click();
					} else {
						pageContents.find('#form').message({
							type : 'error',
							content : data.msg
						});
					}
				});
			});
		});
	</script>
</div>

